﻿using System;
using System.Collections.Generic;

using NUnit.Framework;
using NUnit.Framework.SyntaxHelpers;

using Quiziqal.Domain;
using Quiziqal.Persistence;
using Quiziqal.Testing;

using SharpArch.Core.PersistenceSupport;

namespace Quiziqal.Specifications.Persistence
{
    [TestFixture]
    public class when_saving_question : DatabaseSpecBase
    {
        Question toDb;
        QuestionRepository repository = new QuestionRepository();
        const string BODY = "What is the airspeed velocity of an unladen swallow?";

        protected override void EstablishContext()
        {
            toDb = new Question(BODY);
        }

        protected override void Act()
        {
            repository.SaveOrUpdate(toDb);
            FlushSessionAndEvict(toDb);
        }

        [Test]
        public void should_be_able_to_retrieve_question()
        {
            var fromDb = repository.Get(toDb.ID);

            fromDb.ShouldNotBeNull("retrieved question should not be null");
            fromDb.ShouldNotBeTheSameAs(toDb);
        }
    }
}
